<#
 #   It is recommended to test the script on a local machine for its purpose and effects. 
 #   ManageEngine Endpoint Central will not be responsible for any 
 #   damage/loss to the data/setup based on the behavior of the script.

 #   Description: Script is designed to fetch the hardware hash
 #   Configuration Type - COMPUTER
#>

[CmdletBinding()]
param()

Process
{
	$bad = $false

	# Get a CIM session for the local machine
	$session = New-CimSession

	# Get the hardware hash (if available)
	$devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap -Class MDM_DevDetail_Ext01 -Filter "InstanceID='Ext' AND ParentID='./DevDetail'")
	if ($devDetail)
	{
		$hash = $devDetail.DeviceHardwareData
	}
	else
	{
		$bad = $true
		$hash = ""
	}

	# Write the hardware hash to the pipeline or report an error
	if ($bad)
	{
		Write-Error -Message "Unable to retrieve device hardware data (hash) from the local computer" -Category DeviceError
	}
	else
	{
		Write-Output "Hardware Hash: $hash"
    }

	Remove-CimSession $session
}